<template>
  <view class="course-container">
    <!-- 顶部导航 -->
    <view class="course-header">
      <text class="header-title">人气课程</text>
      <view class="header-actions">
        <uni-icons type="redo" size="24" color="#666"></uni-icons>
        <uni-icons type="more" size="24" color="#666" style="margin-left: 15rpx;"></uni-icons>
      </view>
    </view>

    <!-- 精品课程列表 -->
    <scroll-view class="course-list" scroll-y>
      <!-- 大图课程 -->
      <view class="featured-course">
        <image src="https://s1.aigei.com/prevfiles/fe0c75404d6b4776aa95df8f2fa876d7.png?e=2051020800&token=P7S2Xpzfz11vAkASLTkfHN7Fw-oOZBecqeJaxypL:c8p1DpbBA8zmuDJPShjFAbE6gQk=" mode="aspectFill" class="course-image"></image>
        <view class="course-tag">
          <text>07-01</text>
          <text>98次学习</text>
        </view>
        <view class="course-info">
          <text class="course-title">免费素材【九月下刊】</text>
          <view class="free-tag">免费</view>
        </view>
      </view>

      <!-- 双列课程列表 -->
      <view class="course-grid">
        <view
            v-for="(course, index) in courses"
            :key="index"
            class="course-item"
            @click="goToDetail(course.id)"
        >
          <view class="image-container">
            <image :src="course.image" mode="aspectFill" class="course-thumb"></image>
            <view class="course-tag">{{ course.date }} {{ course.students }}</view>
          </view>
          <view class="course-info">
            <text class="course-title">{{ course.title }}</text>
            <text class="course-subtitle">{{ course.subtitle }}</text>
            <view class="free-tag">免费</view>
          </view>
        </view>
      </view>
    </scroll-view>
  </view>
</template>

<script setup>
import { ref } from 'vue';

const courses = ref([
  {
    id: 1,
    image: "https://s1.aigei.com/prevfiles/fe0c75404d6b4776aa95df8f2fa876d7.png?e=2051020800&token=P7S2Xpzfz11vAkASLTkfHN7Fw-oOZBecqeJaxypL:c8p1DpbBA8zmuDJPShjFAbE6gQk=",
    title: "泰式小漫画 永恒系列",
    subtitle: "美图素材",
    date: "07-01",
    students: "101次学习"
  },
  {
    id: 2,
    image: "https://s1.aigei.com/prevfiles/fe0c75404d6b4776aa95df8f2fa876d7.png?e=2051020800&token=P7S2Xpzfz11vAkASLTkfHN7Fw-oOZBecqeJaxypL:c8p1DpbBA8zmuDJPShjFAbE6gQk=",
    title: "CHRISTMAS DEER YUKI MANGA",
    subtitle: "狐系双眼线款 LU系列-0.07",
    date: "07-01",
    students: "336次观看"
  },
  {
    id: 3,
    image: "https://s1.aigei.com/prevfiles/fe0c75404d6b4776aa95df8f2fa876d7.png?e=2051020800&token=P7S2Xpzfz11vAkASLTkfHN7Fw-oOZBecqeJaxypL:c8p1DpbBA8zmuDJPShjFAbE6gQk=",
    title: "教学视频【极致单根-真我系列】",
    subtitle: "美睫技术精讲",
    date: "07-01",
    students: "177次观看"
  },
  {
    id: 4,
    image: "https://s1.aigei.com/prevfiles/fe0c75404d6b4776aa95df8f2fa876d7.png?e=2051020800&token=P7S2Xpzfz11vAkASLTkfHN7Fw-oOZBecqeJaxypL:c8p1DpbBA8zmuDJPShjFAbE6gQk=",
    title: "免费素材-【六月上刊】",
    subtitle: "专业美睫素材",
    date: "07-01",
    students: "202次学习"
  }
]);

const goToDetail = (id) => {
  uni.navigateTo({
    url: `/pages/course/courseDetail?id=${id}`
  });
};
</script>

<style lang="scss" scoped>
.course-container {
  background-color: #fff;
  min-height: 100vh;
}

.course-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 30rpx;
  position: sticky;
  top: 0;
  z-index: 10;
  background-color: #fff;
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);

  .header-title {
    font-size: 40rpx;
    font-weight: 700;
    color: #333;
    position: relative;
    padding-left: 30rpx;

    &::before {
      content: "";
      position: absolute;
      left: 0;
      top: 50%;
      transform: translateY(-50%);
      width: 10rpx;
      height: 40rpx;
      background-color: #e54d42;
      border-radius: 6rpx;
    }
  }

  .header-actions {
    display: flex;
  }
}

.course-list {
  height: calc(100vh - 90rpx);
  padding: 0 30rpx;
}

.featured-course {
  position: relative;
  border-radius: 20rpx;
  overflow: hidden;
  margin-bottom: 40rpx;
  box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.1);

  .course-image {
    width: 100%;
    height: 380rpx;
  }

  .course-tag {
    position: absolute;
    top: 30rpx;
    left: 30rpx;
    background-color: rgba(229, 77, 66, 0.85);
    color: white;
    padding: 8rpx 20rpx;
    border-radius: 20rpx;
    font-size: 24rpx;
    display: flex;
    gap: 15rpx;
  }

  .course-info {
    position: absolute;
    bottom: 30rpx;
    left: 30rpx;
    right: 30rpx;
    display: flex;
    justify-content: space-between;
    align-items: center;

    .course-title {
      font-size: 36rpx;
      font-weight: 600;
      color: white;
      text-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.3);
    }

    .free-tag {
      background-color: white;
      color: #e54d42;
      padding: 8rpx 24rpx;
      border-radius: 30rpx;
      font-size: 28rpx;
      font-weight: 500;
      box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.2);
    }
  }
}

.course-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 30rpx;
}

.course-item {
  border-radius: 20rpx;
  overflow: hidden;
  box-shadow: 0 6rpx 20rpx rgba(0, 0, 0, 0.08);
  background-color: #fff;
  transition: all 0.3s ease;

  &:active {
    transform: translateY(-10rpx);
    box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.15);
  }

  .image-container {
    position: relative;
    height: 260rpx;

    .course-thumb {
      width: 100%;
      height: 100%;
    }

    .course-tag {
      position: absolute;
      top: 15rpx;
      left: 15rpx;
      background-color: rgba(229, 77, 66, 0.85);
      color: white;
      padding: 6rpx 16rpx;
      border-radius: 20rpx;
      font-size: 22rpx;
    }
  }

  .course-info {
    padding: 20rpx;

    .course-title {
      font-size: 28rpx;
      font-weight: 600;
      color: #333;
      display: -webkit-box;
      -webkit-line-clamp: 1;
      -webkit-box-orient: vertical;
      overflow: hidden;
    }

    .course-subtitle {
      font-size: 24rpx;
      color: #666;
      margin: 10rpx 0;
      height: 70rpx;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      overflow: hidden;
    }

    .free-tag {
      background-color: #fff4f3;
      color: #e54d42;
      padding: 6rpx 20rpx;
      border-radius: 20rpx;
      font-size: 24rpx;
      display: inline-block;
      text-align: center;
    }
  }
}
</style>